/*  File Name	: SignalHanlder.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-4-12
 *  Description:
 */

#ifndef SIGNALHANLDER_H_
#define SIGNALHANLDER_H_

#include <signal.h>
#include "EventHandler.h"

class ReactorImpl;

class SignalHanlder
{
public:
	SignalHanlder();

	virtual ~SignalHanlder();

	int open(ReactorImpl *reactor);

	int register_signal(int signum,EventHandler *sh,bool replace_old,EventHandler *old_sh);

	int remove_signal(int signum,EventHandler *sh);

	int dispatch_signal_handler(int signum);

	int notify_fd(void);

	void close_notify_fd(void);

	EventHandler *handler(int signum);

	static bool is_legal_signal(int signum);

private:
	static void dispatch (int signum, siginfo_t *info,void *p);

	static EventHandler *signal_handlers_[_NSIG];

	static int signal_notify_fd[2];

	ReactorImpl *reactor_;

	EventHandler event_handler_;
};

#endif /* SIGNALHANLDER_H_ */
